<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<jsp:include page="header.jsp" />      
    <div id="inner_wrap">
	<div id="inner_hold">
	<div id="inner">
	<div class="center_hold">
        <jsp:useBean id="productManagement" class="com.aal.model.ProductManagement">
            <jsp:setProperty name="productManagement" property="categoryid" value="${param.categoryid}"/>    
            <jsp:setProperty name="productManagement" property="productname" value="${param.productname}"/>
            <jsp:setProperty name="productManagement" property="unitprice" value="${param.unitprice}"/>
            <jsp:setProperty name="productManagement" property="description" value="${param.description}"/>
            <jsp:setProperty name="productManagement" property="taxpercent" value="${param.taxpercent}"/>
            <jsp:setProperty name="productManagement" property="productimage" value="${param.productimage}"/>
            <jsp:setProperty name="productManagement" property="status" value="${param.status}"/>
            <jsp:setProperty name="productManagement" property="shippingpricecost" value="${param.shippingpricecost}"/>
        </jsp:useBean>
        <jsp:useBean id="categoryManagement" class="com.aal.model.CategoryManagement">
        </jsp:useBean>
        <c:if test="${!empty param.productname && param.hidden =='create'}">
            <jsp:getProperty name="productManagement" property="addproduct"/>
            
        </c:if> 
        <c:if test="${!empty param.productname && param.hidden =='edit'}">
            <jsp:getProperty name="productManagement" property="editproduct"/>
        </c:if>
        <jsp:useBean id="productstatus" class="com.aal.model.ProductStatus"/>          
        <form>
            <fieldset>
                <legend>product Management</legend>
                <input type="hidden" name="hidden" value="create"/>
                <label>Category Name:</label>
                <select name="categoryid">
                    <c:forEach items="${categoryManagement.viewAll}" var="item">
                        <option value="<c:out value='${item.categoryID}'/>">${item.categoryName}</option>
                    </c:forEach>
                </select>
                </br>
                <label for="productname">product Name:</label>
                <input type="text" name="productname" placeholder="Insert product name" required/></br>
                <label for="unitprice">unit Price:</label>
                <input type="text" name="unitprice" placeholder="Insert Unit Price" required/></br>
                <label for="description">description:</label>
                <input type="text" name="description" placeholder="Insert description" required/></br>
                <label for="taxpercent">tax Percent:</label>
                <input type="text" name="taxpercent" placeholder="Insert tax Percent" required /></br>
                <label for="productimage">product Image:</label>
                <input type="file" name="productimage"/></br>
                <label>Status:</label>
                <select name="status">
                    <option value="<c:out value="${productstatus.avaliable}"/>">AVALIABLE</option>
                    <option value="<c:out value="${productstatus.unAvalible}"/>">UNAVALIABLE</option>
                </select></br>
                <label for="shippingpricecost">shipping price cost:</label>
                <input type="text" name="shippingpricecost" placeholder="Insert shippingpricecost" required/></br>
                <input type="submit" value="Create Product"/>
            </fieldset>
        </form>
                <hr/>
        <form>
            <fieldset>
                <legend>product Management</legend>
                <input type="hidden" name="hidden" value="edit"/>
                <label>Category Name:</label>
                <select name="categoryid">
                    <c:forEach items="${categoryManagement.viewAll}" var="item">
                        <option value="<c:out value='${item.categoryID}'/>">${item.categoryName}</option>
                    </c:forEach>
                </select>
                </br>
                <label for="productname">product Name:</label>
                <input type="text" name="productname" placeholder="Insert product name" required/></br>
                <label for="unitprice">unit Price:</label>
                <input type="text" name="unitprice" placeholder="Insert Unit Price" required/></br>
                <label for="description">description:</label>
                <input type="text" name="description" placeholder="Insert description" required/></br>
                <label for="taxpercent">tax Percent:</label>
                <input type="text" name="taxpercent" placeholder="Insert tax Percent" required /></br>
                <label for="productimage">product Image:</label>
                <input type="file" name="productimage"/></br>
                <label>Status:</label>
                <select name="status">
                    <option value="<c:out value="${productstatus.avaliable}"/>">AVALIABLE</option>
                    <option value="<c:out value="${productstatus.unAvalible}"/>">UNAVALIABLE</option>
                </select></br>
                <label for="shippingpricecost">shipping price cost:</label>
                <input type="text" name="shippingpricecost" placeholder="Insert shippingpricecost" required/></br>
                <input type="submit" value="Edit Product"/>
            </fieldset>
        </form>
                <hr/>
        <form>
            <fieldset>
            <legend>product Management</legend>
            <input type="hidden" name="hidden" value="searchbyname"/>
                <label for="productName">product Name</label>
                <input type="text" name="productname"/></br>
                <input type="submit" name="Search product by name"/>  
            </fieldset>
        </form>
                <c:if test="${!empty param.productname && param.hidden == 'searchbyname'}">
                    <table class="bordered">
                    <c:forEach items="${productManagement.searchproductbyname}" var="item">
                        <tr>
                            <td><c:out value="${item.productName}"/></td><td><c:out value="${item.unitPrice}"/></td>
                            <td><c:out value="${item.description}"/></td><td><c:out value="${item.taxPercent}"/></td>
                            <td><c:out value="${item.shippingPriceCost}"/></td><td><c:out value="${item.status}"/></td>
                        </tr>
                    </c:forEach>
                    </table>
                </c:if>
        <hr/>
        <form>
            <fieldset>
                <legend>product Management</legend>
                <input type="hidden" name="hidden" value="viewall"/>
                <input type="submit" value="View all"/>
            </fieldset>
        </form>
        <c:if test="${ param.hidden == 'viewall'}">
                    <table class="bordered">
                        <c:forEach items="${productManagement.listallproducts}" var="item">
                        <tr>
                            <td><c:out value="${item.productName}"/></td><td><c:out value="${item.unitPrice}"/></td>
                            <td><c:out value="${item.description}"/></td><td><c:out value="${item.taxPercent}"/></td>
                            <td><c:out value="${item.shippingPriceCost}"/></td><td><c:out value="${item.status}"/></td>
                        </tr>
                    </c:forEach>
                    </table>
        </c:if>
        <form>
            <fieldset>
                <legend>product Management</legend>
                <input type="hidden" name="hidden" value="searchbycategory"/>
                <label>Category Name:</label>
                <select name="categoryid">
                    <c:forEach items="${categoryManagement.viewAll}" var="item">
                        <option value="<c:out value='${item.categoryID}'/>">${item.categoryName}</option>
                    </c:forEach>
                </select></br>
                <input type="submit" value="search by category"/>
            </fieldset>
        </form>
        <c:if test="${!empty param.categoryid && param.hidden == 'searchbycategory'}">
                    <table class="bordered">
                        <c:forEach items="${productManagement.searchproductbycategory}" var="item">
                        <tr>
                            <td><c:out value="${item.productName}"/></td><td><c:out value="${item.unitPrice}"/></td>
                            <td><c:out value="${item.description}"/></td><td><c:out value="${item.taxPercent}"/></td>
                            <td><c:out value="${item.shippingPriceCost}"/></td><td><c:out value="${item.status}"/></td>
                        </tr>
                    </c:forEach>
                    </table>
        </c:if>
                
    </div>
	</div>
	</div>
	</div>
<jsp:include page="footer.jsp" />